var page = require('webpage').create();
var system = require('system');

cookies = system.args[1];
address = system.args[2];

var cookieStr = "";
cookieObjs = JSON.parse(cookies)
for (var i = cookieObjs.length - 1; i >= 0; i--) {
    cookieStr += cookieObjs[i].Name + ":" + cookieObjs[i].Value + ";"
}

page.onResourceRequested = function(requestData, request) {
    request.setHeader('Cookie', cookieStr)
};

page.settings.userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) ALLL/537 (KHTML, like Gecko) Chrome/46.0.2924.87 Safari/537.36"
page.open(address, function (status) {
    if (status !== 'success') {
        phantom.exit(0);
    } else {
        setTimeout(function(){
            page.render("123.png")
            console.log(address)
            var cookies = page.cookies;
            console.log('<==========>')
            console.log(JSON.stringify(cookies))
            console.log('<==========>')
            var fingerprint = page.evaluate(function() {
                var finger = "";
                new Fingerprint2().get(function(l){finger=l})
                return finger
            });
            console.log(fingerprint)
            console.log('<==========>')
            phantom.exit(0)
        }, 10000)
    }
});
